from django.db import models
from ckeditor.fields import RichTextField
from ckeditor_uploader.fields import RichTextUploadingField
# Create your models here.
# class Title_qap(models.Model):
#     title=models.CharField(max_length=60,verbose_name='标题')
#     weight=models.IntegerField(default=1010,verbose_name='权重')
#     clickCount=models.IntegerField(default=0,verbose_name='点击量')
#     satisfactionCount=models.IntegerField(default=0,verbose_name='满意')
#     unsatisfationCount=models.IntegerField(default=0,verbose_name='不满意')
#
#     def __str__(self):
#         return ('%s --%s ')%(self.title,self.weight)
#     class Meta:
#         verbose_name='标题'
#         verbose_name_plural='标题'

class Key_qap(models.Model):
    word=models.CharField(max_length=30,verbose_name='关键字',unique=True)
    weight = models.IntegerField(default=1010, verbose_name='权重')
    clickCount = models.IntegerField(default=0, verbose_name='点击量')
    satisfactionCount = models.IntegerField(default=0, verbose_name='满意(预留)')
    unsatisfationCount = models.IntegerField(  default=0, verbose_name='不满意(预留)')

    def __str__(self):
        return ('%s --%s')%(self.word,self.weight)

    class Meta:
        verbose_name='关键字'
        verbose_name_plural='关键字'

class QueAnsPairs(models.Model):
    title=models.CharField(max_length=60,verbose_name='标题')
    content=RichTextUploadingField(verbose_name='回答')
    keyWord = models.ManyToManyField(Key_qap, verbose_name='关键字')
    setDate=models.DateTimeField(verbose_name='创建时间',auto_now_add=True)
    updateDate=models.DateTimeField(verbose_name='最后更新时间',auto_now=True)
    satisfactionCount=models.IntegerField(default=0,verbose_name='满意量')
    unsatisfactionCount=models.IntegerField(default=0,verbose_name='不满意量')


    def __str__(self):
        return ('%s-%s-%s')%(self.title,self.keyWord,self.content)

    class Meta:
        verbose_name='问答对'
        verbose_name_plural='问答对'
        unique_together=('title','content')

